home *** CD-ROM | disk | FTP | other *** search
/ GFX Sensations 1 / Graphic Sensations - Volume 1.iso / tools / amiga / fractals / rm2.lha / read.me < prev    next >
Encoding:
Text File  |  1994-01-01  |  8.8 KB  |  184 lines

  1.  
  2. denbeste@world.std.com : Steven C. Den Beste
  3.  
  4. "rm2.c": This is based on the program "retmand" which someone else posted
  5. recently. I could not have done this without him, and I hereby announce
  6. my gratitude. Nonetheless, I suspect that this is so dramatically modified
  7. at this point that the original author wouldn't recognize it.
  8. this point that the original author wouldn't recognize it.
  9.  
  10. The original program just drew the entire Mandelbrot drawing, using random
  11. colors each time. That's all it did - but to do that it had to implement
  12. the entire algorithm for CALCULATING it, and all the code
  13. for displaying stuff on the Retina. Those are the parts I couldn't have
  14. handled. In particular, it used the smart algorithm for calculating
  15. the Mandelbrot diagram (the one which optimizes square sections) instead
  16. of the stupid algorithm (the one which calculates each point every time).
  17. the stupid algorithm (the one which calculates each point every time).
  18.  
  19. What I DO know how to do is enhance, clean up, and optimize. But to do that
  20. I had to perform some modifications. First and foremost: The original code was
  21. written for the SAS compiler. I've got
  22. Aztec C 5.0. Regrettably, they aren't compatible. For a while I tried
  23. to maintain compatibility with #ifdef's, but that got so complex that
  24. I finally gave up and deleted everything non-aztec, so this code is
  25. thoroughly MANXified now. Adapting this back to SAS is probably going to be
  26. a pain.
  27.  
  28. The core of any Mandelbrot program is a routine which iterates a
  29. rather strange function, waiting until the value of the function
  30. exceeds a certain threshold. The value it returns is the integer
  31. count of the number of loops it took for this to take place. All the
  32. calculations are done in floating point. As a result, Mandelbrot programs
  33. have a tendency to take enormous amounts of time unless handled well.
  34. One finds implementations using fixed-point integers, but these
  35. lead to strange results where the program has a "floor" of detail, for
  36. instance. Using floating point prevents this flaw.
  37. tance. Using floating point prevents this flaw.
  38. The innermost loop of this function can iterate literally millions of
  39. times depending on the area you are viewing and the dimensions of the
  40. screen. Any tiny gains in this function can have significant results in
  41. the total compute time.
  42.  
  43. So I dug out my 68882 manual and got to work. It's in ASM now in a separate
  44. module (another reason it's probably going to be hard to re-SASify). 
  45. My code is optimized to
  46. take advantage of the '882's capability to perform simultaneous operations.
  47. (Don't worry - it works just fine for an '881 - it just takes longer.)
  48. The big win is that there are 8 registers out there, and I can
  49. store a lot of values permanently in the FPU - effectively,
  50. they become "register double" variables.
  51.  
  52. It is possible that  more juice can be squeezed out of this routine, and
  53. even a microsecond or two can make a big difference.
  54. I invite anyone who is into this sort of thing to try. I'm a programmer
  55. by profession, and we tend to avoid ASM like the plague because
  56. it is almost always too expensive to debug. (We use it for interrupt
  57. routines, task switchers and not a hell of a lot else.)
  58.  
  59. As with the original, this program uses the default screen size for 8-bit screens,
  60. as set with "RetinaScreenMode".
  61.  
  62. In the mean time I've added a bunch of features. There are now a bunch
  63. of parameters you can specify on the command line, as follows:
  64.  
  65. /r number    - specify the "r" (actually horizontal) value of the CENTER
  66.           of the screen. Negative is left. Values range from about
  67.           minus 2 to plus 2.
  68.  
  69. /i number    - specify the "i" (actually vertical) value of the CENTER
  70.           of the screen. Negative is up. Values range from about
  71.           minus 1 to plus 1.
  72.  
  73. /w number    - specify the width of the screen in "r" coordinate terms.
  74.           The vertical size is computed to maintain an aspect ratio
  75.           of 1.2 to 1.
  76.  
  77. I made /r and /i specify the CENTER deliberately. If you can locate the
  78. center of a feature, it is convenient to generate the frames
  79. of a zoom movie, since all you have to do is change the "w" value. If
  80. /r and /i specified the upper left corner, that would be a royal pain.
  81. (The names "R" and "I" for these coordinates were established by Mandelbrot
  82. himself, and are maintained here for historical reasons.)
  83.  
  84. If you don't specify any of the above three parameters, you get the entire
  85. Mandelbrot diagram.
  86.  
  87. /c number    - Choose a color set. Frankly, right now I'm not very happy
  88.           with the ones I've chosen. If you don't specify anything,
  89.           you get a standard set I think works fairly well. If you
  90.           specify "/c 0" you get the random color set the old program
  91.           would have given you by default. The others are somewhat
  92.           obscure. There is plenty of opportunity here for enhancement.
  93.  
  94. /q          Use a quarter of the screen. Actually a misnomer - this
  95.           divides the screen linearly by 4, so it divides the area
  96.           by 16. Use this when you're trying to home in on /r and /i
  97.           values for interesting features to cut way down on the
  98.           compute time.
  99.  
  100. /h          Use a half (that is, 1/4 by area) of the screen.
  101.  
  102. /t number      Raise the top of the drawing. The default is 256. Values
  103.           above 256 will cause the color set to recycle. Values can
  104.           be specified up to 32767. Please note that depending on the
  105.           image you are computing, raising this value can radically
  106.           slow down compute time.
  107.  
  108. /d number      Often used with "/t". This takes the output of the
  109.           function and divides it by the parameter for every pixel.
  110.           In essence it is lowering the color thresholds. For instance,
  111.           "/d 3" means that the first color threshold represents the
  112.           first THREE step-values, the second represents the
  113.           next THREE step-values, and so on. This does not alter
  114.           the time to compute the drawing, but it can alter its
  115.           image quite a bit.
  116.  
  117. /s filename      If this parameter is NOT present, then when the picture is
  118.           completely drawn it will stay on the screen until you hit
  119.           the "ENTER" key. If this parameter IS present, then when
  120.           the image is complete it will be written out as a 24-bit
  121.           PPM file, and then this program will automatically terminate.
  122.           This means if you want to create the frames for a zoom
  123.           movie, you can set up a batch file and let it run overnight,
  124.           or for a week, or for a month, or for ...
  125.           WARNING: These files are ENORMOUS. You can chew up disk space
  126.           really fast. The file takes 3 bytes per pixel. An
  127.           800*600 frame is 1.5 megabytes (sigh). You might want to make
  128.           your batch file alternate between creating files with this
  129.           program and crunching them with "lha", which can typically
  130.           collapse such a file to 100 Kb or less, depending on
  131.           image complexity. Alternatively, you can use "ppmtogif"
  132.           which won't do as well as "lha" but leaves them in a
  133.           displayable form. By definition these files always have
  134.           fewer than 256 colors, so "ppmtogif" won't ever tell you
  135.           to go use "ppmquant" first.
  136.  
  137. /m threshold      What happens if the Mandelbrot threshold of 4.0 is modified?
  138.           Beats heck out of me, but this parameter allows you to
  139.           experiment. (My early experimenting shows that values above
  140.           about 2.1 all act about the same, and below 1.9 the whole
  141.           image turns black.)
  142.  
  143. To get you started, here are some interesting parameter values to try:
  144.  
  145. /r -.93402 /i -.247638 /w .00004 /d 2 /t 512
  146.  
  147. /r -.5554 /i -.5292 /w .006
  148.  
  149. /r -1.2909 /i -.0861 /w .00155
  150.  
  151. /r -.6763 /i -.36742 /w .0003
  152.  
  153. /r -676204 /i -.367276 /w .000017
  154.  
  155. /r -.6762039 /i -.3672763 /w .0000021 /d 2 /t 512    or
  156. /r -.6762039 /i -.3672763 /w .0000021 /d 3 /t 768
  157.  
  158. Even with all the optimization, these are not going to be fast drawings,
  159. but the results are spectacular (in my own highly biased opinion). These
  160. tended to take more than half an hour on my system at 800*600. Your
  161. mileage may vary. (My system is a GVP G-force 68040 at 33 MHZ running
  162. burst mode, so a 25 MHZ 68030 is probably going to run 4 or 5 times
  163. as long.)
  164.  
  165. If you find any interesting coordinates and feel like doing so, please send
  166. them to me via email at the address at the top line. Bugs are likewise of
  167. interest.
  168.  
  169. Oh, I also added a hell of a lot of comments.
  170. There ARE a few comments here which are not mine, but you'll
  171. pick up on my style rapidly. Where there's a chance of confusion, I'll
  172. include my initials: SCDB.
  173.  
  174. ...and for my next trick: The one obvious need here is a simple way to pick
  175. out the coordinate of some object, so as to center and zoom on that object.
  176. The obvious way to do that is to use the mouse. Well, I can't. To do that
  177. I have to turn on a Sprite, and the part of the Retina includes for that
  178. uses a standard SAS include named "utility/tagitem.h", which Aztec doesn't
  179. have. I can't find the equivalent structure ("struct TagItem") or define
  180. ("TAG_USER") anywhere in the include structure I've got and I haven't got
  181. the faintest idea of what they should be. If someone can tell me, I'll try
  182. to put it in. In the mean time, the only way to home in on objects is to use
  183. "/q" and to tweak the "/r" and "/i" values.
  184.